package reflection;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Test03 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException {
        Class<?> c1 = Class.forName("reflection.User");

        //获取类的名字
        System.out.println(c1.getName());

        Field[] declaredFields = c1.getDeclaredFields();
        for(Field field:declaredFields){
            System.out.println(field);
        }
        System.out.println(c1.getDeclaredField("name")); //获得所有声明的 私有的也可以获得

        Method getName = c1.getMethod("getName", null);
        Method setName=c1.getMethod("setName", String.class);//重载需要类型判断
        System.out.println(getName);


    }
}
